package com.wectrls;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.servlet.MultipartConfigElement;
import java.io.File;

@SpringBootApplication
@EnableScheduling
public class WectrlsServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(WectrlsServiceApplication.class, args);
    }


    /**
     * 适配window和linux环境下的缓冲区
     *
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {

        String tempUrl = "";
        String systemType = System.getProperty("os.name").toLowerCase();
        if (systemType.contains("window")) {
            tempUrl = "C:\\temp\\";
        } else if (systemType.contains("linux")) {
            tempUrl = "/tmp/";
        }
        File temp = new File(tempUrl);
        if (!temp.exists()) {
            temp.mkdirs();
        }
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation(tempUrl);
        MultipartConfigElement multipartConfig = factory.createMultipartConfig();
        return multipartConfig;
    }
}
